package redick;

import redick.parser.*;
import redick.lexer.*;
import redick.node.*;
import java.io.*;


public class Compiler {

	public static String getLine() {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		try   {
			do {
				System.out.print("> ");
				line = in.readLine();
			} while (line.trim().equals(""));

			return line;
		} catch(Exception e) {
			String excp_txt = "Exception: " + e.getMessage();
			System.out.println(excp_txt);
			return excp_txt;
		}
	}

	public static void main(String[] arguments)     {
		String expr;

		for (; ;) {
			expr = getLine();

			try {
				//			Create a Parser instance.
				Parser p = new Parser(new Lexer(new PushbackReader(new StringReader(expr))));


				Start tree = null;
				try 	{
					// Parse the input.
					tree = p.parse();
				}
				catch(Exception e) {
					System.out.println("parse::Exception: " + e.getMessage());
				}

				// Apply the translation.
				tree.apply(new Translation());

			}
			catch(Exception e) {
				System.out.println("main::Exception: " + e.getMessage());
			}
		}
	}
}
